package com.peress.mycrew.rowing.util;

public final class Range<T extends Comparable<T>> {
    private T mMin;
    private T mMax;
    private T mCurrent;

    public Range(T min, T max, T current) {
        mMin = min;
        mMax = max;
        mCurrent = current;
        if (!isValid(this)) {
            throw new IllegalStateException("Invalid range: " + this);
        }
    }

    public T getMin() { return mMin; }
    public T getCurrent() { return mCurrent; }
    public T getMax() { return mMax; }

    public void setMin(T min) { mMin = min; }
    public void setCurrent(T current) { mCurrent = current; }
    public void setMax(T max) { mMax = max; }

    @Override
    public String toString() {
        return new StringBuilder("[").append(mMin).append(", ").append(mCurrent).append(", ")
                .append(mMax).append("]").toString();
    }

    public static boolean isValid(Range r) {
        return r.mMin.compareTo(r.mMax) <= 0 && r.mMin.compareTo(r.mCurrent) <= 0
                && r.mCurrent.compareTo(r.mMax) <= 0;
    }
}
